package com.hmall.service;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hdmall.business.common.util.AgentUtil;
import com.hdmall.business.common.common.ResponseCode;
import com.hdmall.business.common.common.ServerResponse;
import com.hdmall.business.common.common.TokenCache;
import com.hdmall.business.common.util.ImageRecog;
import com.hdmall.business.common.util.MD5Util;
import com.hmall.mapper.*;
import com.hmall.model.*;
import com.hmall.util.*;
import com.hmall.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Service
public class UserService {

    private final SysUserMapper userMapper;

    private final SysUserRoleMapper sysUserRoleMapper;
    private final MallOrderMapper orderMapper;
    private final MallOrderItemMapper orderItemMapper;

    private final SysUserDetailMapper sysUserDetailMapper;

    private final SysUserTempMapper sysUserTempMapper;

    private final SysDeptMapper sysDeptMapper;

    private final SysUserDeptMapper sysUserDeptMapper;


    private final
    JedisPool jedisPool;

    @Autowired
    public UserService(SysUserMapper userMapper, SysUserRoleMapper sysUserRoleMapper, MallOrderMapper orderMapper, MallOrderItemMapper orderItemMapper, SysUserDetailMapper sysUserDetailMapper, SysUserTempMapper sysUserTempMapper, SysDeptMapper sysDeptMapper, SysUserDeptMapper sysUserDeptMapper, JedisPool jedisPool) {
        this.userMapper = userMapper;
        this.sysUserRoleMapper = sysUserRoleMapper;
        this.orderMapper = orderMapper;
        this.orderItemMapper = orderItemMapper;
        this.sysUserDetailMapper = sysUserDetailMapper;
        this.sysUserTempMapper = sysUserTempMapper;
        this.sysDeptMapper = sysDeptMapper;
        this.sysUserDeptMapper = sysUserDeptMapper;
        this.jedisPool = jedisPool;
    }

    public ServerResponse<String> delete(String account){
        List<SysUser> userList= userMapper.selectAccout(account);
        if(null==userList||userList.size()==0){
            return  ServerResponse.createByErrorCodeMessage(-1,"查询用户失败");

        }
        for(SysUser user:userList){
            try {
                userMapper.deleteUser(user.getUserId());
            } catch (Exception e) {
                e.printStackTrace();
                return  ServerResponse.createByErrorCodeMessage(-1,"用户删除失败");
            }
            sysUserDeptMapper.deleteByUserId(user.getUserId());
            sysUserDetailMapper.deleteByUserId(user.getUserId());
            sysUserRoleMapper.deleteByUserId(user.getUserId());
            sysUserTempMapper.deleteByUserId(user.getUserId());
            orderMapper.deleteByUserId(user.getUserId());
            orderItemMapper.deleteByUserId(user.getUserId());
        }

        return  ServerResponse.createBySuccess("删除用户成功");
    }
    public ServerResponse<Map<String, String>> login(String agentUserName, String password) {
        //带了设备头  ANDROID- , IOS- , PC-
        String str[] = AgentUtil.deleteAgentUserName(agentUserName).getData().split(":");
        String agent = str[0];
        String username = str[1];


        if(agent == null) return ServerResponse.createByStatus(19, "未知设备,无法登陆");


           int count = userMapper.checkUsername(username);
            if(count <= 0)
            return ServerResponse.createByStatus(11, "用户名不存在");


        String md5Password = MD5Util.MD5EncodeUtf8(password);

        SysUser user  = userMapper.selectLogin(username,md5Password);


        if(user == null){
            return ServerResponse.createByErrorMessage("密码错误");
        }

        //必须用加密的密码登录
        user.setPassword(md5Password);

        Jedis jedis = jedisPool.getResource();

        String userToken =  DataFomateUtil.sysUserToString(user);
        jedis.setex(agentUserName + "REDIS_USER", 24 * 1000 * 3600 , userToken);

        // 检查是否已经登陆，如果已经登陆，就不用创建新Token并设置过期时间，如果是过期了，
        //为了测试设为30天  安卓和IOS需要登录永远有效
        String accessToken = jedis.get(agentUserName);
        //如果token在redis中没设置，设置到redis中
        if(accessToken == null) {
            accessToken = TokenUtil.createJwtToken(agentUserName);
            // Token超时间隔设为24小时
            if(agent.equals("PC-")) {
                jedis.setex(agentUserName, 24 * 1000 * 3600 , accessToken);
            } else {
                jedis.setex(agentUserName, 24 * 1000 * 3600 * 365 * 10 , accessToken);
            }

        }
        //如果token已经有了取出来

        jedis.close();

       Map<String, String> tokenMap = new HashMap<>();
       tokenMap.put("nickName", user.getQuestion());
       tokenMap.put("avator",  user.getAvatar());
       tokenMap.put("token", accessToken);

       int userId = user.getUserId();

       int status;
       SysUserTemp sysUserTemp = sysUserTempMapper.selectByUserId(userId);
       if(sysUserTemp == null) status = 0;
       else status = sysUserTempMapper.queryStatus(userId);
       tokenMap.put("status", String.valueOf(status));
        return ServerResponse.createBySuccess(tokenMap);
    }

    public ServerResponse<String> register(SysUser user){

        //校验用户名
        ServerResponse validResponse = this.checkValid(user.getUsername());
        if(!validResponse.isSuccess()){
            return validResponse;
        }
        // user.setRole(Const.Role.ROLE_CUSTOMER);
        // MD5加密

        user.setPassword(MD5Util.MD5EncodeUtf8(user.getPassword()));

        //默认昵称
        user.setQuestion(user.getUsername());
        String DEFAULT_AVATOR = "http://hd-yun.oss-cn-hangzhou.aliyuncs.com/imgupload/1542330401567.png?Expires=1857690395&OSSAccessKeyId=LTAI0AE4IXlOaSaX&Signature=9KAS%2FMn7D8buLbLkjdZKW9jX3Lc%3D";
        user.setAvatar(DEFAULT_AVATOR);
        //插入
        try {
            userMapper.myInsert(user);
        }catch(Exception e){
            return ServerResponse.createByStatus(18, "用户信息注册失败");
        }

        int userId=userMapper.selectIdByUsername(user.getUsername());

        SysUserRole userRole =new SysUserRole();
        userRole.setUserId(userId);
        userRole.setRoleId(2);
        try {
            sysUserRoleMapper.insert(userRole);
        } catch (Exception e){
            return ServerResponse.createByStatus(18, "用户权限注册失败");
        }

        return ServerResponse.createBySuccessMessage("注册成功");
    }


    /*
     * 运营商号段如下：
     * 中国联通号码：130、131、132、145（无线上网卡）、155、156、185（iPhone5上市后开放）、186、176（4G号段）、
     *               175（2015年9月10日正式启用，暂只对北京、上海和广东投放办理）
     * 中国移动号码：134、135、136、137、138、139、147（无线上网卡）、150、151、152、157、158、159、182、183、187、188、178
     * 中国电信号码：133、153、180、181、189、177、173、149 虚拟运营商：170、1718、1719
     * 手机号前3位的数字包括：
     * 1 :1
     * 2 :3,4,5,7,8
     * 3 :0,1,2,3,4,5,6,7,8,9
     * 总结： 目前java手机号码正则表达式有：
     * a :"^1[3|4|5|7|8][0-9]\\d{4,8}$"    一般验证情况下这个就可以了
     * b :"^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013678])|(18[0,5-9]))\\d{8}$"
     * Pattern和Matcher详解（字符串匹配和字节码）http://blog.csdn.net/u010700335/article/details/44616451
     */
    private ServerResponse<String> checkValid(String userName){
            //开始校验
        String regex = "^1[3|4|5|7|8][0-9]\\d{4,8}$";
        if(userName.length() != 11){
            return ServerResponse.createByStatus(18,"请输入正确的手机号码");
        }else{
            Pattern p = Pattern.compile(regex);
            Matcher m = p.matcher(userName);
            boolean isMatch = m.matches();
            if(!isMatch){
                return ServerResponse.createByStatus(18,"请输入正确的手机号码");
            }
        }

                int resultCount = userMapper.checkUsername(userName);
                if(resultCount > 0 ){
                    return ServerResponse.createByErrorMessage("用户名已存在");
                }

        return ServerResponse.createBySuccessMessage("可以注册");
    }

    public ServerResponse selectQuestion(String username){

        ServerResponse validResponse = this.checkValid(username);
        if(validResponse.isSuccess()){
            //用户不存在
            return ServerResponse.createByErrorMessage("用户不存在");
        }
        String question = userMapper.selectQuestionByUsername(username);
        if(org.apache.commons.lang3.StringUtils.isNotBlank(question)){
            return ServerResponse.createBySuccess(question);
        }
        return ServerResponse.createByErrorMessage("找回密码的问题是空的");
    }

    public ServerResponse<String> checkAnswer(String username,String question,String answer){
        int resultCount = userMapper.checkAnswer(username,question,answer);
        if(resultCount>0){
            //说明问题及问题答案是这个用户的,并且是正确的
            String forgetToken = UUID.randomUUID().toString();
            TokenCache.setKey(TokenCache.TOKEN_PREFIX+username,forgetToken);
            return ServerResponse.createBySuccess(forgetToken);
        }
        return ServerResponse.createByErrorMessage("问题的答案错误");
    }

    public ServerResponse<String> forgetResetPassword(String username,String passwordNew,String forgetToken){
        if(org.apache.commons.lang3.StringUtils.isBlank(forgetToken)){
            return ServerResponse.createByErrorMessage("参数错误,token需要传递");
        }
        ServerResponse validResponse = this.checkValid(username);
        if(validResponse.isSuccess()){
            //用户不存在
            return ServerResponse.createByErrorMessage("用户不存在");
        }
        String token = TokenCache.getKey(TokenCache.TOKEN_PREFIX+username);
        if(org.apache.commons.lang3.StringUtils.isBlank(token)){
            return ServerResponse.createByErrorMessage("token无效或者过期");
        }

        if(org.apache.commons.lang3.StringUtils.equals(forgetToken,token)){
            String md5Password  = MD5Util.MD5EncodeUtf8(passwordNew);
            int rowCount = userMapper.updatePasswordByUsername(username,md5Password);

            if(rowCount > 0){
                return ServerResponse.createBySuccessMessage("修改密码成功");
            }
        }else{
            return ServerResponse.createByErrorMessage("token错误,请重新获取重置密码的token");
        }
        return ServerResponse.createByErrorMessage("修改密码失败");
    }

    public ServerResponse<String> resetPassword(String passwordOld,String passwordNew,SysUser user){
        //防止横向越权,要校验一下这个用户的旧密码,一定要指定是这个用户.因为我们会查询一个count(1),如果不指定id,那么结果就是true啦count>0;
        int resultCount = userMapper.checkPassword(MD5Util.MD5EncodeUtf8(passwordOld),user.getUserId());
        if(resultCount == 0){
            return ServerResponse.createByErrorMessage("旧密码错误");
        }

        user.setPassword(MD5Util.MD5EncodeUtf8(passwordNew));
        int updateCount = userMapper.updateByPrimaryKeySelective(user);
        if(updateCount > 0){
            return ServerResponse.createBySuccessMessage("密码更新成功");
        }
        return ServerResponse.createByErrorMessage("密码更新失败");
    }

    public ServerResponse<SysUser> updateInformation(SubUserInfoVo subUserInfoVo, Integer userId){
        //username是不能被更新的
        //email也要进行一个校验,校验新的email是不是已经存在,并且存在的email如果相同的话,不能是我们当前的这个用户的.
      /*  int resultCount = userMapper.checkEmailByUserId(user.getEmail(),user.getUserId());
        if(resultCount > 0){
            return ServerResponse.createByErrorMessage("email已存在,请更换email再尝试更新");
        }*/
        SysUser user = userMapper.selectByPrimaryKey(userId);
       if(!subUserInfoVo.getNickName().equals("") && subUserInfoVo.getNickName() != null)
           user.setQuestion(subUserInfoVo.getNickName());

       if(!subUserInfoVo.getAvator().equals("") && subUserInfoVo.getAvator() != null)
           user.setAvatar(subUserInfoVo.getAvator());

        try{
            userMapper.updateByPrimaryKey(user);
        } catch (Exception e){
            e.printStackTrace();
            return ServerResponse.createByStatus(15, "用户信息更新失败");
        }

        return ServerResponse.createBySuccess();
    }

    //获得用户基础信息
    public ServerResponse<UserInfoVo> getInformation(Integer userId){
        SysUser user = userMapper.selectByUserId(userId);
        if(user == null){
            return ServerResponse.createByErrorMessage("找不到当前用户");
        }


        UserInfoVo userInfoVo = new UserInfoVo();
        userInfoVo.setAvator(user.getAvatar());
        //question字段用来做昵称
        userInfoVo.setNickName(user.getQuestion());
        userInfoVo.setPhone(user.getPhone());
        userInfoVo.setEmail(user.getEmail());

        //暂时在这里判断
        SysUserTemp userTemp = sysUserTempMapper.selectByUserId(userId);
        if(userTemp != null) ServerResponse.createByStatus(16 , "用户信息已提交，请勿重复提交");
       // 0 :未提交审核 1:审核中 2: 审核失败 3: 审核通过 4: 资质取消
        if(userTemp == null) {
            userInfoVo.setStatus(0);
        } else{
            userInfoVo.setStatus(userTemp.getStatus());
        }

        return ServerResponse.createBySuccess(userInfoVo);
    }

    //backend
    /**
     * 校验是否是管理员
     * @param user
     * @return
     */
    public ServerResponse checkAdminRole(SysUser user){
        //if(user != null && user.getRole().intValue() == Const.Role.ROLE_ADMIN){
        if(user != null ){
            return ServerResponse.createBySuccess();
        }
        return ServerResponse.createByError();
    }

    //所有详细的User数据
    public ServerResponse<SysUser> hardUserByUsername(String username) {
        SysUser user = userMapper.hardUserByUsername(username);
        if (user != null) {
            return ServerResponse.createBySuccess(user);
        } else {
            return ServerResponse.createByError();
        }
    }

    //用以判断是否已经登录的User部分数据(拦截)
    public ServerResponse<SysUser> simpleUserByUsername(String username){
        SysUser user = userMapper.simpleUserByUsername(username);
      //  System.out.println("user" + user.toString());

        if(user != null){
            return ServerResponse.createBySuccess(user);
        }else{
            return ServerResponse.createByError();
        }
    }



    //
    public ServerResponse<Map<String, String>> getUser(Integer userId) {

        int status;
        SysUserTemp sysUserTemp = sysUserTempMapper.selectByUserId(userId);
        if(sysUserTemp != null){
                status = sysUserTempMapper.queryStatus(userId);
            }else{
               status = 0;
            }
        Map<String, String> map = new HashMap<>();
        map.put("status", String.valueOf(status));
        if(status == 3) map.put("message", "资质通过");
        else if(status == 0) map.put("message", "未提交审核");
        else if(status == 1) map.put("message", "审核中");
        else map.put("message", "审核取消");
        return ServerResponse.createBySuccess(map);

    }

    //公司模糊查询
    public ServerResponse<List<Map<String, Object>>> queryCompany(String subName) {

        List<Map<String, Object>> deptName = sysDeptMapper.queryName(subName);
        if(deptName.size() == 0){
            return ServerResponse.createByStatus(88, "找不到公司");
        }

        return ServerResponse.createBySuccess(deptName);

    }

    //完善用户信息
    public ServerResponse  prefectInformation(SysUserTempVo sysUserTempVo, Integer userId) {

        SysUserTemp sysUserTemp = new SysUserTemp();
        sysUserTemp.setUserId(userId);

        SysUserTemp oldUserTemp = sysUserTempMapper.selectByUserId(userId);
        //1. oldUserTemp == null
        //2. oldUserTemp != null 如果状态为 1 表示正在处理中不能提交资质 其他都可以
        //3. oldUserTemp != null 如果状态为 3  将temp表中的状态改为4 取消该资质
        // 删除detail表以及相关联的表
        if(oldUserTemp != null && oldUserTemp.getStatus() == 1) {
            return ServerResponse.createByStatus(16, "资质正在审核中，请勿重复提交");
        } else if(oldUserTemp != null && oldUserTemp.getStatus() == 3){
            //更新上传过的记录 temp表
            oldUserTemp.setStatus(4);


            //如果原先审核已经通过 修改用户的权限为普通用户
            sysUserRoleMapper.updateStatus(userId, 2);


            //修改
            int tempId = sysUserTempMapper.selectByUserId(userId).getTempId();
            sysUserTempMapper.updateStatus(tempId, 4);

            //删除detail表及其关联表保持资质唯一性
            //sysUserDetailMapper.
            sysUserDetailMapper.deleteByUserId(userId);
            sysUserDeptMapper.deleteByUserId(userId);
        }

        sysUserTemp.setAuthUrl(sysUserTempVo.getAuthUrl());
        sysUserTemp.setIdBackUrl(sysUserTempVo.getIdBackUrl());
        sysUserTemp.setIdFaceUrl(sysUserTempVo.getIdFaceUrl());
        sysUserTemp.setLicenseUrl(sysUserTempVo.getLicenseUrl());
        sysUserTemp.setLinkmanName(sysUserTempVo.getLinkmanName());
        sysUserTemp.setLinkmanTel(sysUserTempVo.getLinkmanTel());

        sysUserTemp.setTaxCertUrl(sysUserTempVo.getTaxCertUrl());
        //默认审核中
        sysUserTemp.setStatus(1);
        try {
            sysUserTempMapper.myInsert(sysUserTemp);
        }catch (Exception e) {
            e.printStackTrace();
            return ServerResponse.createByStatus(16, "用户资料上传失败");
        }
        return ServerResponse.createBySuccess();
    }

    public ServerResponse update(SysUser user) {

        return ServerResponse.createBySuccess(userMapper.updateByPrimaryKey(user));
    }

    public ServerResponse getAptExamList(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<SysUserTemp> aptExamList = sysUserTempMapper.selectAllExam();
        PageInfo pageResult = new PageInfo(aptExamList);
        return ServerResponse.createBySuccess(pageResult);
    }

    public ServerResponse getUnExamList(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<SysUserTemp> aptExamList = sysUserTempMapper.selectUnExam();
        PageInfo pageResult = new PageInfo(aptExamList);
        return ServerResponse.createBySuccess(pageResult);
    }

    public ServerResponse getUnpassExamList(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<SysUserTemp> aptExamList = sysUserTempMapper.selectUnpassExam();
        PageInfo pageResult = new PageInfo(aptExamList);
        return ServerResponse.createBySuccess(pageResult);
    }

    public ServerResponse getPassExamList(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<SysUserTemp> aptExamList = sysUserTempMapper.selectPassExam();
        PageInfo pageResult = new PageInfo(aptExamList);
        return ServerResponse.createBySuccess(pageResult);
    }

   //营业执照
    public ServerResponse<List<ImgLicense>> licImgCastWord(String url) {
        //返回的参数有可能是没有有可能是识别错误FailInRecognition
        
        JSONObject res_obj = null;

        String err = "FailInRecognition";

        try {
            res_obj = ImageRecog.imgLicense(url);
        }catch (Exception e){
            return ServerResponse.createByErrorMessage("营业执照识别失败");
        }
        if(res_obj == null){
            return ServerResponse.createByErrorMessage("营业执照识别失败");
        }

        ImgLicense imgLicense = new ImgLicense();

        String addr = (String) res_obj.get("address");
        if(addr == null || addr.equals(err)) {
            imgLicense.setAddress("");
        }else {
            imgLicense.setAddress(addr);
        }
        
        String bus = (String) res_obj.get("business");
        if(bus == null || bus.equals(err)){
            imgLicense.setBusiness("");
        }else {
            imgLicense.setBusiness(bus);
        }
        
        String capital = (String) res_obj.get("capital");
        if(capital == null || capital.equals(err)){
            imgLicense.setCaptial("");
        }else {
            imgLicense.setCaptial(capital);
        }

        String name = (String) res_obj.get("name");
        if(name == null || name.equals(err)){
            imgLicense.setName("");
        }else {
            imgLicense.setName(name);
        }

        String person = (String) res_obj.get("person");
        if(person == null || person.equals(err)){
            imgLicense.setPerson("");
        }else {
            imgLicense.setPerson(person);
        }

        String establishDate = (String) res_obj.get("establish_date");
        if(establishDate == null || establishDate.equals(err)){
            imgLicense.setEstablishDate("");
        }else {
            String strEstablishDate = establishDate.substring(0, 4) + "/" + establishDate.substring(4, 6) + "/" + establishDate.substring(6, 7);

            imgLicense.setEstablishDate(strEstablishDate);
        }


        String validPeriod = (String) res_obj.get("valid_period");
        if(validPeriod == null || validPeriod.equals(err)){
            imgLicense.setValidPeriod("");
        }else {
            String strValidPeriod = validPeriod.substring(0, 4) + "/" + validPeriod.substring(4, 6) + "/" + validPeriod.substring(6, 7);

            imgLicense.setValidPeriod(strValidPeriod);
        }

        String regNum = (String) res_obj.get("reg_num");
        if(regNum == null || regNum.equals(err)){
            imgLicense.setRegNum("");
        }else {
            imgLicense.setRegNum(regNum);
        }

        String requestId = (String) res_obj.get("request_id");
        if(requestId == null || requestId.equals(err)){
            imgLicense.setRequestId("");
        }else {
            imgLicense.setRequestId(requestId);
        }


         if(res_obj.get("success") == null) {
            imgLicense.setSuccess("false");
         }else{
            imgLicense.setSuccess(res_obj.get("success").equals("true") ? "success" : "false");
         }

        
        

       // imgLicenseMapper.insert(imgLicense);
        List<ImgLicense> imgLicenseList = new ArrayList<>();


        imgLicenseList.add(imgLicense);
        return ServerResponse.createBySuccess(imgLicenseList);
    }

    public ServerResponse<ImgLegalId> idImgCastWord(String url, String config) {

        JSONObject res_obj = null;
        try {
            res_obj = ImageRecog.imgLegalId(url, config);
        }catch (Exception e){
            return ServerResponse.createByErrorMessage("身份证识别失败");
        }
        System.out.println(res_obj);
        if(res_obj == null) return ServerResponse.createByErrorMessage("身份证识别失败");

        ImgLegalId imgLegalId = new ImgLegalId();

        String nationality = (String) res_obj.get("nationality");

        imgLegalId.setNationality((String) res_obj.get("nationality"));
        imgLegalId.setName((String) res_obj.get("name"));
        imgLegalId.setAddress((String) res_obj.get("address"));
        imgLegalId.setNum((String) res_obj.get("num"));

        return ServerResponse.createBySuccess(imgLegalId);
    }
    /**
     * 查询买方名
     * @return
     */
    ServerResponse<SysDeptVo> findBuyerDept(Integer userId){
        //买方用户id查询部门id
        SysDeptVo deptVo= null;
        try {
            deptVo = sysUserDeptMapper.selectDeptByUserId(userId);
        } catch (Exception e) {
            e.printStackTrace();
            return ServerResponse.createByStatus(ResponseCode.DEPT_SELECT_ISNULL_ERROR.getCode(),ResponseCode.DEPT_SELECT_ISNULL_ERROR.getDesc(),null) ;
        }
        if(null==deptVo){
            return ServerResponse.createByStatus(ResponseCode.DEPT_SELECT_ISNULL_ERROR.getCode(),ResponseCode.DEPT_SELECT_ISNULL_ERROR.getDesc(),null) ;
        }
        return ServerResponse.createBySuccess(deptVo);
    }
   //查询发票
    public ServerResponse<UnitContactVo> selectInvoiceByUser(Integer userId){
        UnitContactVo unitContactVo=null;
        try {
            unitContactVo= sysUserDetailMapper.selectUnitByUserId(userId);
        } catch (Exception e) {
            e.printStackTrace();
            return ServerResponse.createByStatus(ResponseCode.INVOICE_NOT_FOUND.getCode(), ResponseCode.INVOICE_NOT_FOUND.getDesc(),null);
        }
        if(null==unitContactVo){
            return ServerResponse.createByStatus(ResponseCode.INVOICE_NOT_FOUND.getCode(), ResponseCode.INVOICE_NOT_FOUND.getDesc(),null);

        }
        return  ServerResponse.createBySuccess(unitContactVo);

    }

    public ServerResponse<SysUserDetailVo> getPerfectInformation(Integer userId) {

        //资质信息
        SysUserDetailVo userDetailVo = sysUserDetailMapper.selectByUserIdVo(userId);
        if(userDetailVo == null) return ServerResponse.createByStatus(17, "还未通过资质审核，无法查看资质信息");

        return ServerResponse.createBySuccess(userDetailVo);
    }

    //获取审核信息
    public ServerResponse<SysUserTemp> getTempPrefectInformation(Integer userId) {

        SysUserTemp userTemp =  sysUserTempMapper.selectByUserId(userId);

        return ServerResponse.createBySuccess(userTemp);
    }
}
